package com.wang.springframework.util;

/**
 * @author wangjianhua
 * @Description
 * @date 2021/8/25/025 10:35
 **/
public class ClassUtils {

    public static ClassLoader getDefaultClassLoader(){
        ClassLoader cl = null;
        try
        {
            cl = Thread.currentThread().getContextClassLoader();
        }
        catch (Throwable ex)
        {
            // Cannot access thread context ClassLoader - falling back to system class loader...
        }
        if(cl == null){
            // No thread context class loader -> use class loader of this class.
            cl = ClassUtils.class.getClassLoader();
        }
        return cl;
    }

    /**
     * 判断是否为cglib代理的类
     * @param clazz class
     * @return boolean
     */
    public static boolean isCglibProxyClass(Class<?> clazz){
        return (clazz != null && isCglibProxyClassName(clazz.getName()));
    }

    /**
     * 通过名字检查是否为cglib代理的类名
     * @param className className
     * @return boolean
     */
    public static boolean isCglibProxyClassName(String className){
        return (className != null && className.contains("$$"));
    }
}
